<?php
// $Id: hotel.php 406 2012-05-29 05:30:34Z tomqin@gmail.com $

class Html_Action extends Action_Front{
    public $shop_id;

    public function __construct(){
        $this->route = 0;//路由0
    }

    function onDefault(){
        $method = '_'.$this->method;
        if(!method_exists($this, $method)){
            $method = '_index';
        }
        $menus = array(
            'aboutus' => '关于我们',
            'privacy' => '用户协议',
            'apply'   => '商家加盟',
            'sitemap' => '网站地图',
        );
        $this->setVar('menus', $menus);
        $this->setVar('method', $this->method);

        $cachename = join('|', array($this->cityid, $this->action, $this->method));

        $force = array_get_bool($_GET, 'force');
        $this->showCache($cachename, array($this, $method), 86400, $force);
    }

    public function _apply(){
        $this->seoContent('商家加盟');
        $this->render('/html/apply');
    }

    public function _mobile(){
        $this->seoContent('手机速订客');
        $this->render('/html/mobile');
    }

    public function _aboutus(){
        $this->seoContent('关于我们');
        $this->render('/html/aboutus');
    }

    public function _privacy(){
        $this->seoContent('用户协议');
        $this->render('/html/privacy');
    }

    public function _sitemap(){
        if(1 || $this->params == 'waimai'){
            $sql = "SELECT picture, name, shop_id FROM biz_shop WHERE shop_type = 1 AND city_id = '{$this->cityid}' ORDER BY rand()";
            $data = Db::getAll($sql);
            $this->setVar('data', $data);
        }
        $this->seoContent('网站地图');
        $this->render('/html/sitemap');
    }

    public function onApplied(){
        if(array_get_bool($_POST, 'isajax') && array_get_bool($_POST, 'dosubmit')){
           $shopname = array_get_string($_POST, 'shopname');
           $zone_id  = array_get_int($_POST, 'zone_id');
           $address  = array_get_string($_POST, 'address');
           $author   = array_get_string($_POST, 'author');
           $contact  = array_get_string($_POST, 'contact');
           $telphone = array_get_string($_POST, 'telphone');
           $deliver  = array_get_int($_POST, 'deliver');
           $description  = array_get_string($_POST, 'description');
           $memo     = array_get_string($_POST, 'memo');
           if($shopname == $author){
                echo json_encode(array('error'=>-1, 'message'=>'请填写正确的店名和联系人'));
           }elseif(!$zone_id){
                echo json_encode(array('error'=>-2, 'message'=>'所在区域没有填写'));
           }elseif(!preg_match("/^1[358]\d{9}$/i", $contact)){
                echo json_encode(array('error'=>-3, 'message'=>'手机格式错误'));
           }else{
               $data = array(
                    'shopname' => $shopname,
                    'zone_id'  => $zone_id,
                    'address'  => $address,
                    'author'   => $author,
                    'contact'  => $contact,
                    'telphone' => $telphone,
                    'deliver'  => $deliver,
                    'description' => $description,
                    'memo' => $memo,
                    'date' => date("Y-m-d H:i:s"),
                );
                file_put_contents(DATA_DIR.'apply.dat', "\r\n".print_r($data, 1), FILE_APPEND);

                $txt = '店铺加盟：'.$data['shopname'].',联系人：'.$data['author'].'，手机：'.$data['contact'].'，送餐电话：'.$data['telphone'];
                $sms = new SMS;
                $sms->sendSMS(array('15524811286'), $txt);

                echo json_encode(array('error'=>0, 'message'=>'OK'));
           }
        }else{
            jumpto('/html/apply');exit;
        }
    }
}
?>